package com.zhengdongzulin.zuke.app.main.mine

import androidx.lifecycle.rxLifeScope
import com.lxj.androidktx.livedata.StateLiveData
import com.zhengdongzulin.zuke.app.Api
import com.zhengdongzulin.zuke.app.data.MessageData2
import com.zhengdongzulin.zuke.base.BaseViewModel
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

class MessageVm : BaseViewModel() {

    var get_message_list: StateLiveData<MessageData2> = StateLiveData()

    fun get_message_list() {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.GET_MESSAGE_LIST)
                            .toResponse<MessageData2>()
                            .await()
                    get_message_list.postValueAndSuccess(r)
                }, {
            assignment(it, get_message_list)
        }
        )
    }

    var update_status: StateLiveData<String> = StateLiveData()

    fun update_status(id: String) {
        rxLifeScope.launch(
                {
                    var r = RxHttp.postJson(Api.UPDATE_STATUS)
                            .add("id", id)
                            .toResponse<String>()
                            .await()
                    update_status.postValueAndSuccess(r)
                }, {
            assignment(it, update_status)
        }
        )
    }

}